home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / LOGEVENT.AML < prev    next >
Text File  |  1996-07-17  |  5KB  |  201 lines

  1. //--------------------------------------------------------------------
  2. // LOGEVENT.AML
  3. // Log Events, (C) 1993-1996 by nuText Systems
  4. //
  5. // (see Logevent.dox for user help)
  6. //
  7. // Running this macro will cause the editor to log the following editor
  8. // events:
  9. //
  10. //   - log begin
  11. //   - opening files and file manager windows
  12. //   - closing files and file manager windows
  13. //   - saving files
  14. //   - switching the focus to another file or window
  15. //
  16. // Logged events can be viewed by pressing <ctrl f11>, or by running
  17. // Logevent again. The following information is displayed in a log
  18. // window for each event:
  19. //
  20. //   - the date and time the event occurred
  21. //   - the name of the event
  22. //   - the file or directory associated with the event
  23. //
  24. // A menu is displayed on the log window, allowing the log to be
  25. // cleared, removed (uninstalled), copied to an edit window, and
  26. // printed.
  27. //
  28. // The current log is appended to the file Macro\Logevent.log when
  29. // removing the log or exiting the editor.
  30. //
  31. // Usage:
  32. //
  33. // Select this macro from the Macro List (on the Macro menu), or run it
  34. // from the macro picklist <shift f12>
  35. //--------------------------------------------------------------------
  36.  
  37. // compile time macros and function definitions
  38. include bootpath "define.aml"
  39.  
  40. // initial window dimensions
  41. constant log_width  = 72
  42.  
  43. // log filename
  44. constant log_file = "macro\\logevent.log"
  45.  
  46. // colors
  47. constant log_title_color        = color black on gray
  48. constant log_menu_color         = color white on blue
  49. constant log_menu_hotkey_color  = color yellow on blue
  50. constant log_menu_hilite_color  = color white on cyan
  51.  
  52. // if already installed, then view the event log
  53. if prf.logobj then
  54.   queueobject prf.logobj "viewlog"
  55.   return
  56. end
  57.  
  58. // inherit from popup windows
  59. settype "popup"
  60.  
  61. variable logbuffer, oldbuffer
  62.  
  63. // cleanup when the log is removed or the editor is closed
  64. event <destroy>
  65.   // save the current log
  66.   savebuf (bootpath log_file) 'a' logbuffer
  67.   if logbuffer then
  68.     destroybuf logbuffer
  69.   end
  70.   destroyvar "logobj" "prf"
  71. end
  72.  
  73. // log an event
  74. function log (text start)
  75.   addline getdate + ' ' + (gettime -1) + "  " + text:-10 +
  76.           (onname (getbufname))  '' '' logbuffer
  77. end
  78.  
  79. // clear the log and start over
  80. function lclear
  81.   deleteblock '*a'
  82.   log "begin"
  83.   delline
  84. end
  85.  
  86. // remove (uninstall) the log
  87. function lremove
  88.   close
  89.   destroyobject
  90. end
  91.  
  92. // copy the log to a new edit window
  93. function ledit
  94.   close
  95.   editbuf = createbuf
  96.   setbufname (qualify "logevent.txt" oldbuffer)
  97.   gotobuf logbuffer
  98.   copyblock '*a' editbuf 1 1
  99.   gotobuf editbuf
  100.   delline
  101.   openbuf editbuf
  102. end
  103.  
  104. // print the log
  105. function lprint
  106.   print
  107. end
  108.  
  109. // key definitions for the log window
  110. key <ctrl c>  lclear
  111. key <ctrl r>  lremove
  112. key <ctrl e>  ledit
  113. key <ctrl p>  lprint   end
  114.  
  115. // macro help
  116. macrofile = arg 1
  117. key <f1>
  118.   helpmacro macrofile
  119. end
  120.  
  121. // called when the log window is created
  122. function onopen
  123.   setcolor north_title_color  log_title_color
  124.   setcolor menu_color         log_menu_color
  125.   setcolor menu_hotkey_color  log_menu_hotkey_color
  126.   setcolor menu_hilite_color  log_menu_hilite_color
  127.   setframe "+4"
  128.   menubar '' 4
  129.     item "{Ctrl-C}=Clear"     lclear
  130.     item "{Ctrl-R}=Remove"    lremove
  131.     item "{Ctrl-E}=Edit"      ledit
  132.     item "{Ctrl-P}=Print"     lprint
  133.     item "{Esc}=Exit"         close
  134.   end
  135.   if (getcoord 'y') + 2 <= getvidrows then
  136.     sizewindow 0 0 0 2
  137.   end
  138.   setwinctrl "≡" 2
  139.   row (getlines)
  140. end
  141.  
  142. // view the event log
  143. function viewlog
  144.   oldbuffer = getcurrbuf
  145.   popup logbuffer "Event Log" log_width getvidrows - 10 (getcurrobj)
  146. end
  147.  
  148. // create and initialize the log buffer
  149. oldbuffer = getcurrbuf
  150. logbuffer = createbuf
  151. log "begin"
  152. delline
  153. currbuf oldbuffer
  154.  
  155. // make this object_id accessible to edit_fmgr below
  156. prf.logobj = getcurrobj
  157.  
  158.  
  159. // trap edit/fmgr window events
  160. object edit_fmgr
  161.  
  162. // log an event
  163. private function log (text)
  164.   sendobject prf.logobj "log" text
  165. end
  166.  
  167. // trap edit_fmgr events:  onopen, onclose, onsave, onfocus
  168.  
  169. // called after opening files
  170. function onopen (options)
  171.   log "open " + options
  172.   passprev options
  173. end
  174.  
  175. // called before closing files
  176. function onclose
  177.   log "close"
  178.   passprev
  179. end
  180.  
  181. // called before saving files
  182. function onsave
  183.   log "save"
  184.   passprev
  185. end
  186.  
  187. // called after switching files
  188. function onfocus
  189.   log "focus"
  190.   passprev
  191. end
  192.  
  193. // view the event log
  194. key <ctrl f11>
  195.   queueobject prf.logobj "viewlog"
  196. end
  197.  
  198. // stay resident
  199. resident ON
  200. msgbox "Event Log Installed.\nRe-run or press <ctrl f11> to view the log."
  201.